package cn.itcast.daoTest;

import cn.itcast.controller.ItemController;
import cn.itcast.domain.AirPlane;
import cn.itcast.domain.Car;
import cn.itcast.domain.Person;
import cn.itcast.domain.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/applicationContext-*.xml"})
public class PersonTest {

    ApplicationContext ac = new ClassPathXmlApplicationContext("spring/applicationContext-tx.xml");

//    @Autowired
//    private Person person;
//
//    @Autowired
//    private Person person2;
//
//    @Autowired
//    private User user;
//
//    @Autowired
//    private User user2;

//    @Autowired
//    private Car car2;


    @Test
    public void test1(){
//        System.out.println("+++++++++++++++++++++++++++");
//        System.out.println(person == person2);
    }

    @Test
    public void test2(){
//        System.out.println(user);
//        System.out.println(user2);
//        System.out.println(user == user2);

        User user = (User)ac.getBean("user");
        System.out.println(user);

        User user2 = (User)ac.getBean("user02");
        System.out.println(user2);
        User user3 = (User)ac.getBean("user03");
        System.out.println(user3);

        User user4 = (User)ac.getBean("user4");
        Car car = user4.getCar();
        System.out.println(car.getCarName()+car.getColor()+car.getPrice());

        car = (Car)ac.getBean("car1");
        System.out.println(car);

//        ApplicationContext ac2 = new AnnotationConfigApplicationContext();
//        Car car2 = (Car)ac2.getBean("Car");
//        System.out.println(car2);
        Person person = (Person)ac.getBean("person2");
        System.out.println(person);

        AirPlane airPlane = (AirPlane)ac.getBean("airPlane");
        System.out.println(airPlane);

        airPlane = (AirPlane)ac.getBean("airPlane2");
        System.out.println(airPlane);

        car = (Car)ac.getBean("car2");
        System.out.println(car);

        ApplicationContext ioc = new ClassPathXmlApplicationContext("spring/applicationContext-service.xml");

        ItemController itemController = (ItemController)ioc.getBean("itemController");
        System.out.println(itemController);




    }

}
